<template>
  <view class="login-container">
    <view class="form-box">
      <text class="title">登录</text>
      <view class="input-item">
        <input type="text" placeholder="请输入用户名" v-model="username" />
      </view>
      <view class="input-item">
        <input type="password" placeholder="请输入密码" v-model="password" />
      </view>
      <button class="login-btn" @click="handleLogin">登录</button>
      <navigator url="/pages/register_page/register/register" class="nav-link">没有账号？去注册</navigator>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
	  account:null
    }
  },
  onShow() {
  	console.log("组件页");
	uni.getStorage({
		key:'UserName',
		success(result) {
			console.log("获取字段成功："+result);
			this.account=result.data
		},
		fail(errMsg) {
			console.log("获取字段失败："+JSON.stringify(errMsg));
		}
	})
  },
  methods: {
    handleLogin() {
		console.log("handleLogin()-->登陆验证");
      if (!this.username || !this.password) {
		  console.log("handleLogin()-->登陆验证");
        uni.showToast({
          title: '请输入用户名和密码',
          icon: 'none'
        })
        return
      }
	  console.log("handleLogin()-->登陆验证"+this.username);
      // 模拟登录成功后跳转到主页面
      uni.showToast({
        title: '登录成功',
        icon: 'success'
      })
      setTimeout(() => {
        uni.navigateTo({ // 若主页面是 tabBar 页面，用 switchTab；否则用 navigateTo
          url: '/pages/register_page/welcome/welcome'
        })
      }, 1500)
    }
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f8f8f8;
}
.form-box {
  width: 80%;
  background-color: #fff;
  padding: 30rpx;
  border-radius: 12rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}
.title {
  display: block;
  text-align: center;
  font-size: 40rpx;
  font-weight: bold;
  margin-bottom: 40rpx;
}
.input-item {
  margin-bottom: 30rpx;
}
.input-item input {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #ddd;
  border-radius: 6rpx;
  padding: 0 20rpx;
  box-sizing: border-box;
}
.login-btn {
  width: 100%;
  height: 80rpx;
  background-color: #007aff;
  color: #fff;
  border-radius: 6rpx;
  margin-bottom: 20rpx;
}
.nav-link {
  display: block;
  text-align: center;
  font-size: 28rpx;
  color: #007aff;
}
</style>